.PHONY: all clean run

all: main main-g++

#++++++++Use of ar Problems+++++++++++++++
# "-L" indicates search dir when link.
# "-l" search lib "1-module" for symbols needed.
# if you use "g++ -L. -o main -l1-module -l2-module main.o",
# then g++ will report:
# -------------------------------
# main.o: In function `main':
# main.cpp:(.text+0xa8): undefined reference to `f1()'
# main.cpp:(.text+0xad): undefined reference to `f3()'
# -------------------------------
# becasue gcc reads symbols from left to right  when link in the 
# link parameter list.
#
main: main.o 1-module.a 2-module.a
	g++ -L. -o main main.o -l1-module -l2-module 
#	"g++ -L. -o main -l1-module -l2-module main.o" can't work

#+++++++If use of ordinary g++, NO Problem.++++++++
main-g++: main.o 1-module.o 2-module.o
	g++ -o main-g++ 1-module.o 2-module.o main.o

main.o: main.cpp head.h
	g++ -c main.cpp -o main.o

1-module.a: 1-module.cpp head.h
	g++ -c 1-module.cpp -o 1-module.o
	ar rcs lib1-module.a 1-module.o

2-module.a: 2-module.cpp head.h
	g++ -c 2-module.cpp -o 2-module.o
	ar rcs lib2-module.a 2-module.o

clean:
	rm -f main *.o *.a main-g++
run:
	@echo "---------run main----------";
	@./main
	@echo "---------run main-g++----------";
	@./main-g++
